package com.terrynoya.fight.stateMachine.controllers
{
	import com.terrynoya.fight.char.Character;
	import com.terrynoya.fight.evaluation.Expression;
	import com.terrynoya.fight.stateMachine.StateController;
	import com.terrynoya.fight.stateMachine.controllers.attrParser.StateCtrlParserType;

	public class ChangeAnim2 extends StateController
	{
		public function ChangeAnim2(name:String)
		{
			super(name);
		}
		
		override protected function initAttrConvertMap():void
		{
			this.attrConvertMap.put("value",StateCtrlParserType.Expression);
		}
		
		override public function run(character:Character):void
		{
			var valueExp:Expression = this.getExpression("value");
			var aniId:int = valueExp.excute(character);
			if(!this.hasExpression("value"))
			{
				return;
			}
			if(character.stateManager.foreignMachine == null)
			{
				return;
			}
			var elemId:int = 0;
			if(this.hasExpression("elem"))
			{
				var elemExp:Expression = this.getExpression("value");
				elemId = valueExp.excute(character);
			}
			
			var eleIndex:int = elemId - 1;
			if(eleIndex < 0)
			{
				eleIndex = 0;
			}
			
			character.setForeignAnimation(character.stateManager.foreignMachine.character.animationManager,aniId,eleIndex);
		}
	}
}